package com.isunland.managesystem.adapter;

import android.graphics.Color;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import butterknife.BindView;
import com.amulyakhare.textdrawable.TextDrawable;
import com.isunland.managesystem.R;
import com.isunland.managesystem.base.BaseButterKnifeAdapter;
import com.isunland.managesystem.base.BaseVolleyActivity;
import com.isunland.managesystem.entity.ZTreeNode;
import com.isunland.managesystem.utils.MyStringUtil;
import java.util.ArrayList;

/**
 * 已完成工作列表适配器
 *
 * @author wu
 */
public class ColorTagAdapter extends BaseButterKnifeAdapter<ZTreeNode> {
  // Constructors
  public ColorTagAdapter(BaseVolleyActivity context, ArrayList<ZTreeNode> objects) {
    super(context, objects);
  }

  @Override protected int setLayoutId() {
    return R.layout.adapter_color;
  }

  @NonNull @Override protected BaseViewHolder initHolder(View convertView) {
    return new ViewHolder(convertView);
  }

  @Override protected void initView(ZTreeNode item, BaseViewHolder baseHolder, int position) {
    ViewHolder holder = (ViewHolder) baseHolder;
    holder.tvName.setText(item.getName());
    //holder.ivColor.setBackgroundColor(Color.parseColor(item.getExtParam()));
    holder.ivColor.setImageDrawable((!MyStringUtil.contains(item.getExtParam(), "#")) ? null
        : TextDrawable.builder().buildRound("", Color.parseColor(item.getExtParam())));
  }

  protected class ViewHolder extends BaseViewHolder {
    @BindView(R.id.iv_color) ImageView ivColor;
    @BindView(R.id.tv_name) TextView tvName;

    ViewHolder(View view) {
      super(view);
    }
  }
}

